 package com.example.safeassistan.risk.fragment;

 import android.content.Context;
 import android.graphics.drawable.BitmapDrawable;
 import android.os.Build;
 import android.os.Bundle;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.LinearLayout;
 import android.widget.PopupWindow;
 import android.widget.RelativeLayout;
 import android.widget.TextView;
 import android.widget.Toast;

 import androidx.annotation.NonNull;
 import androidx.annotation.RequiresApi;
 import androidx.recyclerview.widget.LinearLayoutManager;
 import androidx.recyclerview.widget.RecyclerView;

 import com.chad.library.adapter.base.BaseQuickAdapter;
 import com.example.safeassistan.R;
 import com.example.safeassistan.base.BaseVPFragment;
 import com.example.safeassistan.constants.UrlConstants;
 import com.example.safeassistan.home.activity.ActivityBacksecond;
 import com.example.safeassistan.home.activity.HiddenDangerinvestigation;
 import com.example.safeassistan.home.activity.RiskPointDetail;
 import com.example.safeassistan.home.activity.RiskPointList;
 import com.example.safeassistan.home.activity.WarnningList;
 import com.example.safeassistan.home.adapter.BackLogAdapter;
 import com.example.safeassistan.home.model.InvestigationModel;
 import com.example.safeassistan.home.model.MyBackLogListModel;
 import com.example.safeassistan.http.HttpRequest;
 import com.example.safeassistan.http.HttpStringCallBack;
 import com.example.safeassistan.login.activity.LoginPasswordActivity;
 import com.example.safeassistan.risk.adapter.RiskMyListAdapter;
 import com.example.safeassistan.risk.adapter.RiskPointTableDetailListPAdapter;
 import com.example.safeassistan.risk.model.RiskPointLevelStatModel;
 import com.example.safeassistan.risk.model.RiskPointListSearchModel;
 import com.example.safeassistan.risk.model.RiskPointTableDetailModel;
 import com.example.safeassistan.utile.JsonUtils;
 import com.scwang.smartrefresh.layout.SmartRefreshLayout;
 import com.scwang.smartrefresh.layout.api.RefreshLayout;
 import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
 import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

 import org.json.JSONException;
 import org.json.JSONObject;

 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;

 import static com.example.safeassistan.constants.Constants.PAGESIZE;

 public class RiskPointTableDetailFragment extends BaseVPFragment {
    private Context context;
    private View view;
    private RiskPointTableDetailListPAdapter adapter;
    private List<RiskPointListSearchModel.ResultDTO.RecordsDTO> data;
    private RecyclerView rcView;
    private String checkTableId="";
    private String dangerRiskPointId="";
    private String riskPointId="";
    private LinearLayout llNodata;

    public static RiskPointTableDetailFragment newInstance(String dangerRiskPointId,String riskPointId,String checkTableId) {
        Bundle arguments = new Bundle();
        arguments.putString("dangerRiskPointId",dangerRiskPointId);
        arguments.putString("riskPointId",riskPointId);
        arguments.putString("checkTableId",checkTableId);
        RiskPointTableDetailFragment fl = new RiskPointTableDetailFragment();
        fl.setArguments(arguments);
        return fl;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (view == null) {
            view = inflater.inflate(R.layout.fragment_riskdetail_risk, container, false);
            context = getActivity();
            initView();
        }
        return view;
    }

    public void initView(){
        Bundle bundle = getArguments();
        checkTableId=bundle.getString("checkTableId");
        riskPointId=bundle.getString("riskPointId");
        llNodata=view.findViewById(R.id.llNodata);
        dangerRiskPointId=bundle.getString("dangerRiskPointId");
        rcView=view.findViewById(R.id.rcView);
        //rcView.setNestedScrollingEnabled(false);
        getData();
    }

    @Override
    protected void onFragmentVisibleChange(boolean isVisible) { }

    @Override
    protected void onFragmentFirstVisible() {
    }


        public void getData(){
            JSONObject map=new JSONObject();
            try {
                map.put("checkTableId",checkTableId);
                if (!dangerRiskPointId.equals("")){
                    map.put("dangerRiskPointId",dangerRiskPointId);
                }
                map.put("riskPointId",riskPointId);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        new HttpRequest(context).doPost(UrlConstants.queryAgendaTaskDetails, null,map, new HttpStringCallBack() {
            @RequiresApi(api = Build.VERSION_CODES.M)
            @Override
            public void onSuccess(Object result) {
                String datas = result.toString();
                JSONObject jsonObject = null;
                try {
                    jsonObject = new JSONObject(datas);
                    String message = jsonObject.getString("message");
                    Boolean success = jsonObject.getBoolean("success");
                    if (success) {
                        Object obj = JsonUtils.fromJson(result.toString(), InvestigationModel.class);
                        if (obj instanceof InvestigationModel) {
                            InvestigationModel model=(InvestigationModel)obj;
                            if(model.getResult()!=null&&model.getResult().size()>0){
                                llNodata.setVisibility(View.GONE);
                                rcView.setVisibility(View.VISIBLE);
                                adapter=new RiskPointTableDetailListPAdapter(model.getResult());
                                rcView.setAdapter(adapter);
                                rcView.setLayoutManager(new LinearLayoutManager(context));
                            }else {
                                llNodata.setVisibility(View.VISIBLE);
                                rcView.setVisibility(View.GONE);
                            }

                        }
                    }else {
                        Toast.makeText(context,message,Toast.LENGTH_SHORT).show();
                    }
                }catch (Exception e){
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(int code, String msg) {
            }
        });
    }
}